let arr = [
  { name: "张三", age: 18, like: { n: 1 } },
  { name: "李四", age: 19 },
  { name: "王五", age: 20 },
  { name: "赵六", age: 21 },
  { name: "张三", age: 18, like: { n: 1 } },
];

function unique(arr) {
  let res = new Array();
  // 只能处理基本数据类型
  // for (let i = 0; i < arr.length; i++) {
  //     if (!res.includes(arr[i])) {
  //         res.push(arr[i])
  //     } else {
  //         continue
  //     }
  // }
  
  for (let i = 0; i < arr.length; i++) {
    let isFind = false;
    for (let j = 0; j < res.length; j++) {
      if (equal(arr[i], res[j])) {
        isFind = true;
        break;
      }
    }
    if (!isFind) {
      res.push(arr[i]);
    }
  }
  return res;
}

function equal(v1, v2) {
  if (
    typeof v1 === "object" &&
    v1 !== null &&
    typeof v2 === "object" &&
    v2 !== null
  ) {
    if (Object.keys(v1).length !== Object.keys(v2).length) return false;
    for (let key in v1) {
      if (key in v2) {
        if (!equal(v1[key], v2[key])) return false;
      } else {
        return false;
      }
    }
    return true;
  } else {
    return v1 === v2;
  }
}

console.log(unique(arr));